package com.hangim.pce.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * 用法类型
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum UsageType {
    ORAL("ORAL", 1, "口服"),

    INTRAMUSCULAR_PUSH_INJECTION("INTRAMUSCULAR_PUSH_INJECTION", 21, "静脉推注"),
    INTRAMUSCULAR_INJECTION("INTRAMUSCULAR_INJECTION", 2, "肌内注射/肌注/肌内/"),
    INTRVENAOUS_INJECTION("INTRAVENOUS_INJECTION", 3, "静脉注射/静注"),
    HYPODERMIC_INJECTION("HYPODERMIC_INJECTION", 4, "皮下注射/皮下"),
    ACUPOINT_INJECTION("ACUPOINT_INJECTION", 5, "穴位注射"),
    INTRAVENOUS_INFUSION("INTRAVENOUS_INFUSION", 6, "静脉滴注"),
    INTRATRACHEAL_INFUSION("INTRATRACHEAL_INFUSION", 32, "气管内滴注"),

    TOPICAL_ADMINISTRATION("TOPICAL_ADMINISTRATION", 7, "局部给药"),
    EPIDURAL_ADMINISTRATION("EPIDURAL_ADMINISTRATION", 8, "硬膜外给药"),
    INTRATHECAL_ADMINISTRATION("INTRATHECAL_ADMINISTRATION", 9, "鞘内给药"),
    MUCOSA_ADMINISTRATION("MUCOSA_ADMINISTRATION", 10, "粘膜给药"),
    OPHTHALMIC_ADMINISTRATION("OPHTHALMIC_ADMINISTRATION", 11, "经眼给药"),
    SUBLINGUAL_ADMINISTRATION("SUBLINGUAL_ADMINISTRATION", 12, "舌下给药"),
    RECTAL_ADMINISTRATION("RECTAL_ADMINISTRATION", 13, "直肠给药"),
    NASOPHARYNGEAL_DOSING("NASOPHARYNGEAL_DOSING", 14, "鼻咽给药"),
    URETHRAL_DOSING("URETHRAL_DOSING", 15, "尿道给药"),
    INTRAVESICAL_ADMINISTRATION("INTRAVESICAL_ADMINISTRATION", 16, "膀胱给药"),
    SKIN_ADMINISTRATION("SKIN_ADMINISTRATION", 17, "皮肤给药"),
    PERSONALIZED_ADMINISTRATION("PERSONALIZED_ADMINISTRATION", 18, "个性化给药"),
    VAGINA_ADMINISTRATION("VAGINA_ADMINISTRATION", 22, "阴道给药"),

    BAG_OF_SOFT_WATER("BAG_OF_SOFT_WATER", 31, "温开水冲服"),
    BAG_OF_BOIL_WATER("BAG_OF_BOIL_WATER", 19, "开水冲服"),
    WATER_TAKING("WATER_TAKING", 24, "开水送服"),
    WATER("WATER", 30, "冲服"),
    SPRAYED_OUT_OVER("SPRAYED_OUT_OVER", 20, "喷于患处"),
    CHEW_TAKING("CHEW_TAKING", 23, "咀嚼服用/嚼服"),
    BUCCAL("BUCCAL", 25, "含服"),
    SWALLOW("SWALLOW", 26, "吞服"),
    POST_CIBUM("POST_CIBUM", 27, "饭后服"),
    TOPICAL_MEDICATION("TOPICAL_MEDICATION", 28, "外用"),
    EYE_DROPS("EYE_DROPS", 29, "滴于眼睑/滴眼"),

    OTHER("OTHER", 0, "其他");

    // 类型
    private final String code;
    // 描述
    private final String desc;
    // 编号
    private final Integer num;

    UsageType(final String code, final Integer num, final String desc) {
        this.code = code;
        this.desc = desc;
        this.num = num;
    }

    /**
     * 把所有枚举定义转换成实体
     *
     * @return List<RuleLevel>
     */
    public static List<UsageType> getList() {
        List<UsageType> list = Lists.newArrayList();

        UsageType[] ts = UsageType.values();
        for (UsageType type : ts) {
            list.add(type);
        }
        return list;
    }

    public static UsageType getUsageType(String code) {
        UsageType[] ts = UsageType.values();
        for (UsageType t : ts) {
            if (t.getCode().equalsIgnoreCase(code)) {
                return t;
            }
        }
        return OTHER;
    }

    public static UsageType getUsageTypeByDesc(String desc) {
        UsageType[] ts = UsageType.values();
        for (UsageType t : ts) {
            if (t.getDesc().contains(desc)) {
                return t;
            }
        }
        return OTHER;
    }


    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getNum() {
        return num;
    }
}
